﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Compilex.Automata;
using Infraestruturex.Automata;
using Compilex.Syntatic;

namespace UnitTests.Syntatic
{
    public class TestHelper
    {
        public static ITokenProvider GetCexLexer(string source)
        {
            return new Lexer(GetLanguageConfiguration(), source);
        }

        public static Operator[] ParseOperators(string[] lines)
        {
            List<Operator> operators = new List<Operator>();
            foreach (string _operator in lines)
            {
                // OP_ADD +
                string[] elements = _operator.Split(' ');
                operators.Add(new Operator(elements[0], elements[1]));
            }
            return operators.ToArray();
        }


        public static LanguageConfiguration GetLanguageConfiguration()
        {
            string[] keywords = Compilex.Properties.Resource1.keywords.Split(
                new char[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries);
            string[] operators = Compilex.Properties.Resource1.operators_punctuation.Split(
                new char[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries);
            return new LanguageConfiguration(keywords, ParseOperators(operators));
        }

        public static Syntatex BuildSyntatex(string input)
        {
            return Syntatex.Build(input);
        }
    }
}
